package org.maiyoframework.assist.service;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.maiyoframework.assist.dao.UserDao;
import org.maiyoframework.assist.entity.User;
import org.maiyoframework.core.jpa.Condition;
import org.maiyoframework.core.jpa.Finder;
import org.maiyoframework.core.web.page.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserSvcImpl implements UserSvc {
	
	public User save(User entity){
		return dao.save(entity);
	}
	
	public Integer deleteAll(Serializable... ids){
		return dao.deleteAll(ids);
	}
	
	public User deleteById(Serializable id){
		return dao.deleteById(id);
	}
	
	public void delete(User entity){
		dao.delete(entity);
	}
	
	public User update(User entity){
		return dao.saveOrUpdate(entity);
	}
	
	public void updateDynamic(User entity) {
		User bean = dao.updateDynamic(entity);
		bean.setLastLoginTime(new Date());
	}
	
	public User findById(Serializable id){
		return dao.findById(id);
	}
	
	public User findUnique(Finder finder) {
		return dao.findUnique(finder);
	}

	public Page<User> findPage(HttpServletRequest req, Integer pageNo,
			Integer pageSize) {
		Finder finder = new Finder();
		finder.setWhere(new Condition("email like", "%k%"));
		finder.setOrderBy("registerTime", "desc");
		return dao.findPage(finder, req, pageNo, pageSize, -1);
	}

	public List<User> findList(Finder finder, int start, int maxSize) {
		return dao.findList(finder, start, maxSize);
	}

	public List<User> findList(Finder finder) {
		return dao.findList(finder);
	}

	public Long countResult(Finder finder) {
		return dao.countResult(finder);
	}

	@Resource
	private UserDao dao;

}
